package com.ruoyi.info.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.domain.CmsLikes;
import com.ruoyi.info.service.ICmsLikesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点赞Controller
 * 
 * @author xwj
 * @date 2023-07-07
 */
@Controller
@RequestMapping("/news/likes")
public class CmsLikesController extends BaseController
{
    private String prefix = "news/likes";

    @Autowired
    private ICmsLikesService cmsLikesService;

    @RequiresPermissions("news:likes:view")
    @GetMapping()
    public String likes()
    {
        return prefix + "/likes";
    }

    /**
     * 查询点赞列表
     */
    @RequiresPermissions("news:likes:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsLikes cmsLikes)
    {
        startPage();
        List<CmsLikes> list = cmsLikesService.selectCmsLikesList(cmsLikes);
        return getDataTable(list);
    }

    /**
     * 导出点赞列表
     */
    @RequiresPermissions("news:likes:export")
    @Log(title = "点赞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsLikes cmsLikes)
    {
        List<CmsLikes> list = cmsLikesService.selectCmsLikesList(cmsLikes);
        ExcelUtil<CmsLikes> util = new ExcelUtil<CmsLikes>(CmsLikes.class);
        return util.exportExcel(list, "点赞数据");
    }

    /**
     * 新增点赞
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存点赞
     */
    @RequiresPermissions("news:likes:add")
    @Log(title = "点赞", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsLikes cmsLikes)
    {
        return toAjax(cmsLikesService.insertCmsLikes(cmsLikes));
    }

    /**
     * 修改点赞
     */
    @RequiresPermissions("news:likes:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsLikes cmsLikes = cmsLikesService.selectCmsLikesById(id);
        mmap.put("cmsLikes", cmsLikes);
        return prefix + "/edit";
    }

    /**
     * 修改保存点赞
     */
    @RequiresPermissions("news:likes:edit")
    @Log(title = "点赞", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsLikes cmsLikes)
    {
        return toAjax(cmsLikesService.updateCmsLikes(cmsLikes));
    }

    /**
     * 删除点赞
     */
    @RequiresPermissions("news:likes:remove")
    @Log(title = "点赞", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsLikesService.deleteCmsLikesByIds(ids));
    }
}
